<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}管理后台</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <script src="/static/js/bootstrap.bundle.min.js"></script>
</head>
<body class="bg-light">
    <div class="container py-4">
        <h1 class="text-center mb-4">管理后台</h1>
        <!-- 测试内容 -->
        <div class="alert alert-info">
            {% for message in messages %}
            <p>{{ message }}</p>
            {% endfor %}
        </div>
        <!-- 测试内容 -->
        <div class="text-end mb-3">
            <a href="{{ url_for('index') }}" class="btn btn-primary">返回首页</a>
        </div>
        <!-- 用户管理 -->
        <h2>用户管理</h2>
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <thead class="table-dark">
                    <tr>
                        <th>ID</th>
                        <th>用户名</th>
                        <th>管理员</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                    <tr>
                        <td>{{ user.id }}</td>
                        <td>{{ user.username }}</td>
                        <td>{{ '是' if user.get('is_admin') else '否' }}</td>
                        <td>
                            <form method="post" class="d-inline">
                                <input type="hidden" name="action" value="delete_user">
                                <input type="hidden" name="user_id" value="{{ user.id }}">
                                <button type="submit" class="btn btn-danger btn-sm">删除</button>
                            </form>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <!-- 视频管理 -->
        <h2 class="mt-5">视频管理</h2>
        <div class="table-responsive">
            <table class="table table-striped table-bordered">
                <thead class="table-dark">
                    <tr>
                        <th>标题</th>
                        <th>上传者</th>
                        <th>播放次数</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for video in videos %}
                    <tr>
                        <td>{{ video.title }}</td>
                        <td>{{ video.uploader }}</td>
                        <td>{{ video.play_count }}</td>
                        <td>
                            <form method="post" class="d-inline">
                                <input type="hidden" name="action" value="delete_video">
                                <input type="hidden" name="video_filename" value="{{ video.video_filename }}">
                                <button type="submit" class="btn btn-danger btn-sm">删除</button>
                                <a target="_blank" href="{{ url_for('play', video_filename=video['video_filename']) }}" class="btn btn-primary btn-block">观看</a>
                            </form>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>
